//
//  LBColdFilter.mm
//  OpenGLGame
//
//  Created by Nguyen Cong Huy on 3/29/13.
//  Copyright (c) 2013 UIT. All rights reserved.
//

#include "LBColdFilter.h"
#include "LBToneCurveFilter.h"
#include "LBSaturationFilter.h"
#include "LBOverlayTextureFilter.h"
#include "LBHueFilter.h"
#include "LBContrastFilter.h"
#include "AcvFileReader.h"
#include "LBNormalBlendColorFilter.h"
#include "LBUtils.h"

LBColdFilter::LBColdFilter(){
    
    AcvFileReader* acvReader = [[AcvFileReader alloc] initWithACV:@"old-curves"];

    toneCurve = new LBToneCurveFilter();
    toneCurve->setCurveImageData([acvReader toneCurveByteArray]);
    
    gradientOverlay = new LBOverlayTextureFilter();
    gradientOverlay->setOpactiy(0.4);
    
    saturation1 = new LBSaturationFilter();
    saturation1->setSaturation(1.2);
    
    hue = new LBHueFilter();
    hue->setHue(20);
    
    saturation2 = new LBSaturationFilter();
    saturation2->setSaturation(0.15);
    
    normalBlend = new LBNormalBlendColorFilter();
    normalBlend->setColor(0.894, 1.0, 0.0);
    normalBlend->setOpactiy(0.03);
    
    contrast = new LBContrastFilter();
    contrast->setContrast(1.2);
    
    toneCurve->addTarget(gradientOverlay)->addTarget(saturation1)->addTarget(hue)->addTarget(saturation2)->addTarget(normalBlend)->addTarget(contrast);
    firstFilter = toneCurve;
    [acvReader release];
}

LBColdFilter::~LBColdFilter(){
    outputTexture = 0;
    DELETE_SAFELY(toneCurve);
    DELETE_SAFELY(gradientOverlay);
    DELETE_SAFELY(saturation1);
    DELETE_SAFELY(hue);
    DELETE_SAFELY(saturation2);
    DELETE_SAFELY(normalBlend);
    DELETE_SAFELY(contrast);
}

void LBColdFilter::setBlendTexture(LBTexture* blendTexture){
    gradientOverlay->setBlendTexture(blendTexture);
}